package sky.com.util
{
	import flash.display.MovieClip;
	import flash.events.Event;
	
	import mx.controls.Alert;
	import mx.core.MovieClipAsset;
	
	import sky.com.vo.User;

	public class CardFactory
	{
		//发牌动画
		[Embed(source="/mysource/swfsource.swf", symbol="CardDistributionMovie")]
		private static var CardDistributionMovie:Class;
		private static  var cardDistributionMovieIntance:MovieClipAsset;
		private static var cardDistributionMovieFrameNum:Array=[15,35,50,65,75,90,105,125];//发牌动画需要停止的帧
		
		//玩家牌
		[Embed(source="/mysource/swfsource.swf", symbol="UserCard")]
		private static var UserCard:Class;
		
		private static  var user1Card:MovieClipAsset=new UserCard();
		private static  var user2Card:MovieClipAsset=new UserCard();
		private static  var user3Card:MovieClipAsset=new UserCard();
		private static  var user4Card:MovieClipAsset=new UserCard();
		private static  var user5Card:MovieClipAsset=new UserCard();
		private static  var user6Card:MovieClipAsset=new UserCard();
		private static  var user7Card:MovieClipAsset=new UserCard();
		private static  var user8Card:MovieClipAsset=new UserCard();
		private static var userCardArr:Array=[user1Card,user2Card,user3Card,user4Card,user5Card,user6Card,user7Card,user8Card];
		private static var cardXArr:Array=[450,110,30,110,450,778,870,778];
		private static var cardYArr:Array=[468,468,272,84,84,84,272,468];
		
		
		public function CardFactory()
		{
		}
		
		//获取发牌动画实例
		public static function getCardDistributionMovie():MovieClip{
			if(cardDistributionMovieIntance==null){
				cardDistributionMovieIntance=new CardDistributionMovie();
			}
			cardDistributionMovieIntance.gotoAndStop(1);
			cardDistributionMovieIntance.x=470;
			cardDistributionMovieIntance.y=180;
			return cardDistributionMovieIntance;
		}
		
		//给某个位置发一张牌
		public static function distributeCard(pNum:Number,cardDistributionMovie:MovieClip):void{
			cardDistributionMovie.gotoAndPlay("s"+pNum);
			cardDistributionMovie.addEventListener(Event.ENTER_FRAME,cardDistributionMovieEnterFrame);
			//cardDistributionMovie.addEventListener(Event.ENTER_FRAME,function(e:Event){cardDistributionMovieEnterFrame(e,cardDistributionMovie)})
		}
		
		public static function cardDistributionMovieEnterFrame(e:Event):void{
			
			var cardDistributionMc:MovieClip=e.target as MovieClip;
			var k:Number=cardDistributionMc.currentFrame;

			for(var i:Number=0;i<8;i++){
				if(cardDistributionMovieFrameNum[i]==k){
					cardDistributionMc.stop();
					cardDistributionMc.removeEventListener(Event.ENTER_FRAME,cardDistributionMovieEnterFrame);
				}
			}
		}
		
		public static function getUserCard(userNum:Number):MovieClip{
				userCardArr[userNum-1].x=cardXArr[userNum-1];
				userCardArr[userNum-1].y=cardYArr[userNum-1];
				return userCardArr[userNum-1];
		}
		
		
		
	}
}